package org.dawning.shop.category.controller;

import io.swagger.annotations.*;
import org.dawning.shop.category.service.BaseCategoryService;
import org.dawning.shop.core.base.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by L on 2017/6/12.
 */
@RestController
@RequestMapping("/attribute")
public class AttributeController {

    @Autowired
    private BaseCategoryService baseCategoryService;


    @ApiOperation("添加属性类型接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "分类ID",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "name",value = "类型名",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "code",value = "类型编码",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "sort",value = "排序",paramType = "query",dataType = "int")
    })
    @ApiResponse(code=200,message = "返回所在分类信息")
    @RequestMapping(value = "/type/add",method = RequestMethod.POST)
    public BaseResult addType(@RequestParam String id,@RequestParam String name, @RequestParam String code, @RequestParam int sort){
        return baseCategoryService.addType(id,name,code,sort);
    }


    @ApiOperation("删除属性类型接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "分类ID",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "code",value = "类型编码",paramType = "query",dataType = "String")
    })
    @ApiResponse(code=200,message = "返回成功与否")
    @RequestMapping(value = "/type/delete",method = RequestMethod.POST)
    public BaseResult deleteType(@RequestParam String id,@RequestParam(required = false) String code){
        return baseCategoryService.deleteType(id,code);
    }

    @ApiOperation("更新属性类型接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "分类ID",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "name",value = "类型名",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "code",value = "类型编码",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "sort",value = "排序",paramType = "query",dataType = "int")
    })
    @ApiResponse(code=200,message = "返回所在分类信息")
    @RequestMapping(value = "/type/update",method = RequestMethod.POST)
    public BaseResult updateType(@RequestParam String id,@RequestParam String name, @RequestParam String code, @RequestParam int sort){
        return baseCategoryService.updateType(id,name,code,sort);
    }

    @ApiOperation("添加属性接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "分类ID",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "typeCode",value = "类型编码",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "name",value = "属性名",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "code",value = "属性编码",paramType = "query",dataType = "String"),
            @ApiImplicitParam(name = "sort",value = "排序",paramType = "query",dataType = "int")
    })
    @ApiResponse(code=200,message = "返回所在分类信息")
    @RequestMapping(value = "/attribute/add",method = RequestMethod.POST)
    public BaseResult addAttribute(@RequestParam String id,@RequestParam String typeCode,@RequestParam String name, @RequestParam String code, @RequestParam int sort){
        return baseCategoryService.addAttribute(id,typeCode,name,code,sort);
    }
    @ApiOperation("获取所在分类的属性接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "分类ID",paramType = "query",dataType = "String")
    })
    @ApiResponse(code=200,message = "返回所在分类信息")
    @RequestMapping(value = "/attribute/get",method = RequestMethod.POST)
    public BaseResult getAttribute(@RequestParam String id){
        return baseCategoryService.getAttribute(id);
    }

    @ApiOperation("删除属性接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "分类ID",paramType = "query",dataType = "String")
    })
    @ApiResponse(code=200,message = "返回所在分类信息")
    @RequestMapping(value = "/attribute/delete",method = RequestMethod.POST)
    public BaseResult getAttribute(@RequestParam String id,@RequestParam String typeCode,@RequestParam String code){
        return baseCategoryService.deleteAttribute(id,typeCode,code);
    }
}